/**
 * Created by hanpd on 2017/4/26.
 */

import * as constants from '../common/Constants';
import UmfLog from '../utils/UmfLog';
/**
 * 商铺处理状态。
 */
export function  registProcssState(isPos,code) {
    this.code = code;
    if (!code) {
        UmfLog.error("registProcssState error code: " + code);
        return;
    }

    let helpers = {
        _codeFilter: (item)=> {
            return item.code === this.code;
        }
    };

    let filtered = constants.StoreStates.ImPay.filter(helpers._codeFilter);
    if (!isPos&&filtered && filtered.length > 0) {
        //立马付产品
        this.isImPay = true;
        this.title = filtered[0].title;

        /**店铺状态*/
        this.isStoreing = constants.StoreStates.ImPay[0].code === this.code;//待提交店铺
        this.isPhotoing = constants.StoreStates.ImPay[1].code === this.code;//待上传照片
        this.isProducting = constants.StoreStates.ImPay[2].code === this.code;//待开通产品
        this.isInviting = constants.StoreStates.ImPay[3].code === this.code;//待邀请商户
        this.isSigning = constants.StoreStates.ImPay[4].code === this.code;//待商户签约
        //三期新增，个体商户没有待复查状态
        this.isChecking = constants.StoreStates.ImPay[5].code === this.code;//待复查
        //三期新增,待审核、待报备、待配置银商关系都显示待审核
        this.isReviewing = constants.StoreStates.ImPay[6].code === this.code;//待审核
        this.isReporting = constants.StoreStates.ImPay[7].code === this.code;//待报备
        this.isConfigRelation = constants.StoreStates.ImPay[8].code === this.code;//待配置银商关系

        this.isModifying = constants.StoreStates.ImPay[9].code === this.code;//待修改


        /**店铺的步骤*/
        this.storeingDone = !this.isStoreing;//已录入店铺
        this.photoingDone = !this.isStoreing && !this.isPhotoing;//已上传照片
        this.productingDone = !this.isStoreing && !this.isPhotoing && !this.isProducting;//已开通产品
        this.invitingDone = !this.isStoreing && !this.isPhotoing && !this.isProducting && !this.isInviting;//已邀请商户
        this.signingDone = !this.isStoreing && !this.isPhotoing && !this.isProducting && !this.isInviting && !this.isSigning;//已商户签约

        return;
    }

    filtered = constants.StoreStates.Pos.filter(helpers._codeFilter);
    if (isPos&&filtered && filtered.length > 0) {
        //POS产品
        this.isPos = true;
        this.title = filtered[0].title;
        // this.storeingDone = true;
        // this.photoingDone = true;
        // this.productingDone = true;
        this.returned = constants.StoreStates.Pos[0].code === this.code;//退回
        this.rechecking = constants.StoreStates.Pos[1].code === this.code;//审核中
        this.submiting = constants.StoreStates.Pos[2].code === this.code;//未提交
        this.recoding = constants.StoreStates.Pos[3].code === this.code;//审核完成报备中
        this.chargeHandling = constants.StoreStates.Pos[4].code === this.code;//联动手续费配置
        this.terminalDistribing = constants.StoreStates.Pos[5].code === this.code;//联动终端分拨
        this.finished = constants.StoreStates.Pos[6].code === this.code;//完成

        return;
    }

    this.code = null;
    UmfLog.error("registProcssState error code: " + code);
}

export function salemanState(salesmanStatus) {
    this.salesmanStatus = salesmanStatus;
    if (!salesmanStatus) {
        UmfLog.error("salemanState error salesmanStatus: " + salesmanStatus);
        return;
    }

    let helpers = {
        _codeFilter: (item) => {
            return item.code == this.salesmanStatus;
        }
    };

    let filtered = constants.SalesmanStates.filter(helpers._codeFilter);
    if (filtered && filtered.length > 0) {
        this.btnDec = filtered[0].btnDec;
        this.alertMsg = filtered[0].alertMsg;
        this.sideState = filtered[0].sideState;
        this.completeMsg = filtered[0].completeMsg;
    } else {
        this.salesmanStatus = null;
        UmfLog.error("salesmanStatus error salesmanStatus: " + salesmanStatus);
    }
}